#include <iostream>
#include <string>
#include <unistd.h>
#include <stdlib.h>

#include "logging.h"

typedef struct {
	char* ns;
	logging::Level level;
} tester;

void *logtester(void *arg) {
	tester *info = (tester*)arg;

	logging::Log *log = logging::LogManager::getLog(info->ns);
	log->setLevel(info->level);

	//srand( time(0) );

	while ( 1 ) {
		int q = (int)(5 * (double)rand() / (  (double)(RAND_MAX) + (double)(1) ) );
		switch(q) {
		case 4:
			log->debug() << "Debug Message" << logging::end();
			break;
		case 3:
			log->info() << "Info Message" << logging::end();
			break;
		case 2:
			log->warn()  << "Warn Message" << logging::end();
			break;
		case 1: 
			log->error()  << "Error Message" << logging::end();
			break;
		default:
			log->fatal() << "Fatal Message" << logging::end();
			break;
		}
		usleep(50000);
	}
}

int main(void) {
	pthread_t ids[5];	
	tester info[5] = {
			{"test1", logging::log_debug},
			{"test2", logging::log_info},
			{"test3", logging::log_warn},
			{"test4", logging::log_error},
			{"test5", logging::log_fatal}};		

	srand( time(0) );

	for(int i=0; i < 5; i++) {
		pthread_create(&ids[i], NULL, logtester, &info[i]); 
	}

	while ( 1 );

	for(int i=0; i < 5; i++) {
		pthread_join(ids[i], NULL);
	}
        return 0;
}
